/*

Author   : chaos

FileName : tet_val.cpp

Date     : 09/08/17 15:47:37

*/
#include <iostream>
using namespace std;

int det_val(int *arr , int size);

int arr_ele(int *arr ,int size , int col ,int rol);

int main(int argc ,char *argv[])
{
    int arr[3][3] = {{1,1,2},{3,4,5},{6,7,8}};

    cout << "determinant of arr = " << det_val(arr[0],3) << endl;

    return 0;
}

int det_val(int *arr , int size){

    int det = 0, temp;

    for (int i = 0; i < size ; i++) {
        temp = 1;
        for (int j = 0; j < size; j++) {
            temp *= arr_ele(arr,3,i+j,j);
        }

        det += temp;

        temp = 1;
        for(int j=0;j<size;++j){
            temp *= arr_ele(arr,3,i-j,j);
        }

        det -=temp;


    }
    return det;

}


int arr_ele(int *arr , int size ,int col ,int rol){

    while(col < 0) col+=size;
    while(rol < 0) rol+=size;

    if (col>=size)
        col %= size;
    if(rol>=size)
        rol %= size;

    return arr[col*size+rol];
}
